﻿var block = function (id, y, h) {
    this.id = id;
    var colorMap = MusicTheory.Synesthesia.map();
    this.color = '#' + colorMap[this.id].hex;

    block.prototype.CheckId = function () {
        var z1, z2;
        var node = [0, 54, 75, 152, 208, 229, 285, 306, 383, 438, 460, 515];
        z1 = this.id % 12;
        z2 = Math.floor(this.id / 12);
        switch (z1) {
            case 1: case 4: case 6: case 9: case 11:
                this.X = parseInt(node[z1]) + z2 * 539;
                this.W = 47;
                break;
            case 0: case 2: case 3: case 5: case 7: case 8: case 10:
                this.X = parseInt(node[z1]) + z2 * 539;
                this.W = 75; break;
        }
    }

    this.Y = y; // u
    this.H = h;// t
    this.FillStyle;
    this.StrokeStyle;

    block.prototype.Draw = function () {
        ctx.fillStyle = this.color;
        ctx.strokeStyle = 'transparent';
        ctx.lineWidth = 1;
        roundRect(ctx, this.X, this.Y, this.W, this.H, 15, true, true);
        ctx.strokeRect(this.X, this.Y, this.W, this.H);
    }

    function roundRect(ctx, rx, ry, rwidth, rheight, radius, fill, stroke) {
        if (typeof stroke == "undefined") {
            stroke = true;
        }
        if (typeof radius === "undefined") {
            radius = 5;
        }

        ctx.beginPath();
        ctx.moveTo(rx + radius, ry);
        ctx.lineTo(rx + rwidth - radius, ry);
        ctx.quadraticCurveTo(rx + rwidth, ry, rx + rwidth, ry + radius);
        ctx.lineTo(rx + rwidth, ry + rheight - radius);
        ctx.quadraticCurveTo(rx + rwidth, ry + rheight, rx + rwidth - radius, ry + rheight);
        ctx.lineTo(rx + radius, ry + rheight);
        ctx.quadraticCurveTo(rx, ry + rheight, rx, ry + rheight - radius);
        ctx.lineTo(rx, ry + radius);
        ctx.quadraticCurveTo(rx, ry, rx + radius, ry);
        ctx.closePath();
        if (stroke) {
            ctx.stroke();
        }
        if (fill) {
            ctx.fill();
        }
    }
};